<template>
    <h2 style="text-align: center;">用户注册</h2>
    <el-form ref="formRef" :model="form" :rules="rules" lable-width="80px">
        <h3 class="title">系统注册</h3>
        账号：<el-form-item lable="账号" prop="account" style="width: 50%;">
            <el-input v-model="form.account" placeholder="请输入用户名"></el-input>
        </el-form-item>
        密码：<el-form-item lable="密码" prop="password" style="width: 50%;">
            <el-input v-model="form.password" type="password" placeholder="请输入密码" ></el-input>
        </el-form-item>
        确认密码：<el-form-item lable="确认密码" prop="cfpassword" style="width: 50%;">
            <el-input v-model="form.cfpassword" type="password" placeholder="请确认密码"></el-input>
        </el-form-item>
        <el-form-item label="">
            <!-- <el-buttom type="primary" class="w100p" @click="register(formRef)">注册</el-buttom> -->
        </el-form-item>
    </el-form>
</template>

<script setup>
import { ref } from 'vue';
const formRef = ref()
const form = ref({
    account: "",
    password: "",
    cfpassword: "",
})
const rules = ref({
    account: [
        { required: true, message: "请输入用户名", trigger: ["change", "blur"] },
        { pattern: /^[a-zA-Z]{6,10}$/, message: '用户名由英文字母组成,长度为6到10个字符', trigger: ["change", "blur"] },
    ],
    password: {
        required: true,
        min: 6,
        message:"请输入至少六个字符的密码",
        trigger: ["change", "blur"],
    },
    cfpassword: [{
        required: true,
        message: "请确认密码",
        trigger: ["change", "blur"]
    },
    {
        validator: (rule, value, callback) => {
            console.log('value', value);
            console.log('this.form.password', form.value.password);
            if (value !== form.value.password) {
                callback(new Error("两次密码输入不一样"));
            } else {
                callback()
            }
        },
        trigger: ["change", "blur"],
    },
    ]
})
const register = (formEl) => {
    if(formEl){
        formEl.validate((valid) =>{
            if(valid){
            //接口请求
        }
        })  
    }
}

</script>